<#include "common/top.html"/>
<@shiro.hasPermission name="jiaosetianjia">
<div class="layui-form-item layui-form-item-top">
    <button class="layui-btn-tan" id="addOperator">
        <i class="layui-icon">&#xe608;</i> 新增操作员
    </button>
</div>
</@shiro.hasPermission>
<form class="layui-form" action="${basePath}system/role/getRolelistPage" type="0" method="post" name="userForm" id="userForm">
    <@shiro.hasPermission name="jiaosechaxun">
    <div class="searchbox" id="searchbox">
        <input type="text" name="keywords" value="${pd.keywords}" lay-verify="title" autocomplete="off" placeholder="请输入关键字" class="layui-input">

        <input type="button" value="查询" onclick="searchs();" class="layui-btn layui-btn-red"/>
    </div>
</@shiro.hasPermission>
<div class="levTable">
    <table id="simple-table" class="table table-striped table-bordered table-hover">
        <thead>
        <tr>
            <th>序号</th>
            <th>用户姓名</th>
            <th>用户名</th>
            <th>用户角色</th>
            <th>用户状态</th>
            <th style="width: 100px;">操作</th>
        </tr>
        </thead>
        <tbody>
        <#if "${operatorList?has_content}">
            <#list  operatorList as var >
                <tr>
                    <td>${var_index?if_exists+1}</td>
                    <td>${var.operatorName }</td>
                    <td>${var.operatorId }</td>
                    <td>${var.roleName }</td>
                    <td>${var.status }</td>
                    <td>
                        <@shiro.hasPermission name="shouquanjiaose">
                        <a style="font-size: 17px;" class="layui-icon" onclick="editRights('${var.operatorId }');"
                           title="菜单权限">&#xe612;</a>
                    </@shiro.hasPermission>
                    <@shiro.hasPermission name="jiaosexiugai">
                    <a class="layui-icon" onclick="editOperator('${var.operatorId }');" title="修改">&#xe642;</a>
                </@shiro.hasPermission>
                <@shiro.hasPermission name="jiaoseshanchu">
                <a class="layui-icon" onclick="delOperator('${var.operatorId }');" title="删除">&#xe640;</a>
            </@shiro.hasPermission>
            </td>
            </tr>
            </#list>
        </#if>
        </tbody>
    </table>
</div>

<#include "/common/page.html" />
</form>
<script type="text/javascript">
    var rooturl = "${basePath}sysuser/merchant/getOperatorlistPage";
    //检 索
    function searchs() {
        _GLOBE_DATA("reLoadPageParam")(_GLOBE_DATA("createURL")(rooturl, "searchbox"));
    }
    //修改
    function editOperator(operatorId) {
        layer.open({
            type: 2,//此处以iframe举例
            title: '角色编辑',
            area: ['450px', '450px'],
            maxmin: true,
            content: '${basePath}sysuser/role/toRoleEdit?operatorId=' + operatorId,
            btn: ['保存', '关闭'], //只是为了演示
            yes: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.save();
            },
            no: function (index) {
                layer.close(index);
            },
            end: function () {
                reLoadPage(rooturl);
            }
        });
    }

    //删除
    function delOperator(operatorId) {
        layer.confirm('确认要删除吗？', {
            btn: ['确定', '取消']
        }, function (index, layero) {
            var url = "${basePath}sysuser/merchant/deleteOperator?operatorId=" + operatorId;
            $.ajax({
                url: url,
                type: "POST",
                success: function (data) {
                    if (data.status == 'success') {
                        layer.alert(data.msg, function (index) {
                            var index1 = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index1);
                            parent.layer.close(index);
                            reLoadPage(rooturl);
                        });
                    } else {
                        layer.alert(data.msg);
                    }
                }
            })
        });
    }

    //菜单权限
    function editRights(roleId) {
        layer.open({
            type: 2,//此处以iframe举例
            title: '菜单权限',
            area: ['500px', '400px'],
            maxmin: true,
            content: '${basePath}/sysuser/menu/listmenus?roleId=' + roleId,
            btn: ['保存', '关闭'],
            yes: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.save();
            },
            no: function (index) {
                layer.close(index);
            },
            end: function () {
                reLoadPage(rooturl);
            }
        });

    }
    //添加
    $("#addOperator").click(function () {
        layer.open({
            type: 2,//此处以iframe举例
            title: '添加操作员',
            area: ['450px', '450px'],
            maxmin: true,
            content: '${basePath}sysuser/merchant/toAddOperator',
            btn: ['保存', '关闭'], //只是为了演示
            yes: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.save();
            },
            no: function (index) {
                layer.close(index);
            },
            end: function () {
                reLoadPage(rooturl);
            }
        });
    });
</script>
